//
//  EvaluationCell.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/11/23.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "EvaluationCell.h"

@implementation EvaluationCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        for (int i = 0; i < 4; i++) {
            UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake((kWidth/4-64)/2+18+kWidth/4*i, (60-22)/2, 64, 22)];
            [self.contentView addSubview:btn];
            [btn addTarget: self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
            btn.tag = i+1;
            
            NSArray *titles = @[@"全部",@"好评",@"中评",@"差评"];
            btn.layer.masksToBounds = YES;
            btn.layer.cornerRadius = 22/2;
            
            [btn setTitle:titles[i] forState:UIControlStateNormal];
            if (i == 0) {
                [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                btn.titleLabel.font = [UIFont systemFontOfSize:14];
            }else {
                [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                btn.titleLabel.font = [UIFont systemFontOfSize:11];
            }
            if (i == 0||i == 1||i == 2) {
                [btn setBackgroundColor:[UIColor colorWithRed:251/255.0 green:225/255.0 blue:195/255.0 alpha:1]];
                
            }else {
                [btn setBackgroundColor:[UIColor colorWithRed:232/255.0 green:232/255.0 blue:232/255.0 alpha:1]];
            }
        }
    }
    return self;
}
-(void)clickBtn:(UIButton *)clickBtn
{
    if ([self.delegate respondsToSelector:@selector(evaluationCell:withBtn:)]) {
        [self.delegate evaluationCell:self withBtn:clickBtn];
    }
}
- (void)setGoodsCount:(NSInteger)goodsCount
{
    _goodsCount = goodsCount;
    
    UIButton *goodBtn = (UIButton *)[self.contentView viewWithTag:2];
    [goodBtn setTitle:[NSString stringWithFormat:@"好评(%ld)",self.goodsCount] forState:UIControlStateNormal];
}
- (void)setMediumsCount:(NSInteger)mediumsCount
{
    _mediumsCount = mediumsCount;
    UIButton *btn = (UIButton *)[self.contentView viewWithTag:3];
    [btn setTitle:[NSString stringWithFormat:@"中评(%ld)",self.mediumsCount] forState:UIControlStateNormal];
}
- (void)setTerriblesCount:(NSInteger)terriblesCount
{
    _terriblesCount = terriblesCount;
    UIButton *btn = (UIButton *)[self.contentView viewWithTag:1];
    [btn setTitle:[NSString stringWithFormat:@"全部(%ld)",self.goodsCount +self.mediumsCount +self.terriblesCount] forState:UIControlStateNormal];
    UIButton *terriblesBtn = (UIButton *)[self.contentView viewWithTag:4];
    [terriblesBtn setTitle:[NSString stringWithFormat:@"差评(%ld)",self.terriblesCount] forState:UIControlStateNormal];
}
@end
